package com.ruoyi.web.controller.task;

import java.util.List;
import com.ruoyi.common.constant.SysConstants;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.task.domain.SysStep;
import com.ruoyi.task.service.ISysStepService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 步骤信息Controller
 * 
 * @author YJF
 * @date 2022-11-29
 */
@RestController
@RequestMapping("/task/step")
public class SysStepController extends BaseController
{
    @Autowired
    private ISysStepService sysStepService;

    /**
     * 查询步骤信息列表
     */
    @PreAuthorize("@ss.hasPermi('task:step:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysStep sysStep)
    {
        startPage();
        List<SysStep> list = sysStepService.selectSysStepList(sysStep);
        return getDataTable(list);
    }

    /**
     * 查询步骤信息所有未删除的列表
     */
    @PreAuthorize("@ss.hasPermi('task:step:list')")
    @GetMapping("/getAll")
    public AjaxResult getAll(SysStep sysStep)
    {
        List<SysStep> list = sysStepService.selectSysStepList(sysStep);
        return AjaxResult.success(list);
    }
    /**
     * 获取步骤信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('task:step:query')")
    @GetMapping(value = "/{stepId}")
    public AjaxResult getInfo(@PathVariable("stepId") Long stepId)
    {
        return AjaxResult.success(sysStepService.selectSysStepByStepId(stepId));
    }

    /**
     * 新增步骤信息
     */
    @PreAuthorize("@ss.hasPermi('task:step:add')")
    @Log(title = "步骤信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysStep sysStep)
    {
        return toAjax(sysStepService.insertSysStep(sysStep));
    }

    /**
     * 修改步骤信息
     */
    @PreAuthorize("@ss.hasPermi('task:step:edit')")
    @Log(title = "步骤信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysStep sysStep)
    {
        return toAjax(sysStepService.updateSysStep(sysStep));
    }

    /**
     * 修改启用状态
     */
    @PreAuthorize("@ss.hasPermi('task:edit')")
    @Log(title = "修改启用状态", businessType = BusinessType.UPDATE)
    @PostMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody SysStep sysStep)
    {
        return toAjax(sysStepService.updateSysStep(sysStep));
    }

    /**
     * 删除步骤信息
     */
    @PreAuthorize("@ss.hasPermi('task:step:remove')")
    @Log(title = "步骤信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{stepIds}")
    public AjaxResult remove(@PathVariable Long[] stepIds)
    {
        return toAjax(sysStepService.deleteSysStepByStepIds(stepIds));
    }
}
